import tkinter as tk

class TodoApp(tk.Frame):
    def __init__(self, master):
        super().__init__(master)
        self.master  = master
        self.tasks  = []

        # 界面组件
        self.entry  = tk.Entry(master, width=30)
        self.entry.pack(pady=10)

        self.add_btn  = tk.Button(master, text="添加任务", command=self.add_task)
        self.add_btn.pack()

        self.listbox  = tk.Listbox(master, width=40)
        self.listbox.pack(pady=10)

        self.del_btn  = tk.Button(master, text="删除选中", command=self.del_task)
        self.del_btn.pack()

    def add_task(self):
        task = self.entry.get()
        if task:
            self.tasks.append(task)
            self.listbox.insert(tk.END,  task)
            self.entry.delete(0,  tk.END)

    def del_task(self):
        selected = self.listbox.curselection()
        if selected:
            self.listbox.delete(selected[0])

if __name__ == "__main__":
    root = tk.Tk()
    app = TodoApp(root)
    root.mainloop()